import rxAjax from '@/assets/js/ajax.js';
import FormUtil from "@/assets/js/FormUtil";
import {Util} from '@lowcode/jpaas-common-lib';

//表单校验配置 api接口
export const FormRuleApi = {};

FormRuleApi.baseUrl= '/api-form/form/core/formRule';
FormRuleApi.exportUrl= FormRuleApi.baseUrl + '/listExport';


FormRuleApi.doImport=function(formData,callback) {
  var url= FormRuleApi.baseUrl+"/doImport";
  return rxAjax.upload(url,formData,callback);
}


FormRuleApi.doExport = function(solutionIds) {
  solutionIds=Util.encryptWord(solutionIds);
  window.location.href='/api/api-form/form/core/formRule/doExport?solutionIds=' + solutionIds;
}


//查询列表
FormRuleApi.query=function (parameter) {
  var url= FormRuleApi.baseUrl + '/query';
  return rxAjax.postJson(url,parameter).then (res => {
    return res.result
  })
}

FormRuleApi.queryList=function(parameter){
    var url= FormRuleApi.baseUrl + '/queryList';
    return rxAjax.postJson(url,parameter)
}

/**
* 获取单记录
* @param pkId
* @returns {*}
*/
FormRuleApi.get =function(pkId) {
  var url= FormRuleApi.baseUrl + '/get?pkId=' + pkId;
  return rxAjax.get(url);
}

//保存数据
FormRuleApi.save =function(parameter) {
  var url= FormRuleApi.baseUrl + '/save';
  return rxAjax.postJson(url,parameter);
}

//删除数据
FormRuleApi.del =function(parameter) {
  var url= FormRuleApi.baseUrl + '/del';
  return rxAjax.postUrl(url,parameter);
}

//查找所查询的数据并导出
FormRuleApi.listExport= function (parameter){
    var url= FormRuleApi.baseUrl + '/listExport';
    FormUtil.doExport(url,parameter);
}

FormRuleApi.update =function(parameter) {
    var url= FormRuleApi.baseUrl + '/update';
    return rxAjax.postJson(url,parameter);
}

FormRuleApi.updExport =function(ids) {
    var url= FormRuleApi.baseUrl + '/updExport';
    return rxAjax.postForm(url,{ids:ids});
}

export  default FormRuleApi;

